"""Example Visitor Implementation
from http://www.swc.scipy.org/lec/oop02.html
"""

class AbstractCommand(object):
    '''Base class for commands.'''
    def is_undoable(self):
        return False # by default, can't undo/redo operations
    def do(self, robot):
        raise NotImplementedError("Don't know how to do %s" % self.name)
    def undo(self, robot):
        pass
    def redo(self, robot):
        pass

# A particular command        
class MoveCommand(AbstractCommand):
    '''Move the robot arm.'''

    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

    def is_undoable(self):
        return True

    def do(self):
    	print "do",
        print "translate(%i, %i, %i)"%(self.x, self.y, self.z)

    def undo(self):
    	print "undo",
        print "translate(%i, %i, %i)"%(-self.x, -self.y, -self.z)

    def redo(self):
    	print "redo",
        self.do()

def _mod_test():
	commands = [MoveCommand(5.0, 2.0, 2.3),
	            MoveCommand(-90.0, 0.0, 0.0),
	            MoveCommand(1.0, 2.0, 2.0),
	            ]
	for c in commands:
	    c.do()
	    
	for c in commands:
	    c.undo()
	    
	for c in commands:
	    c.redo()
	 
if __name__ == '__main__':
	_mod_test()
	
